package com.yanqu.road.server.cmd.rank;

import com.yanqu.road.entity.grandchild.GrandChildData;
import com.yanqu.road.pb.grandchild.GrandChildProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.config.grandchild.GrandChildMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.pb.GrandChildPb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_GET_GRAND_CHILD_RANK_DETAIL_INFO_FROM_CROSS, desc = "跨服来获取孙子榜单孙子详细信息")
public class GrandChildRankDetailInfoCrossCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        GrandChildProto.GrandChildRankDetailInfoCrossReqMsg reqMsg = GrandChildProto.GrandChildRankDetailInfoCrossReqMsg.parseFrom(packet.getBytes());
        GrandChildData grandChildData = GrandChildMgr.getGrandChildData(reqMsg.getQueryUserId(), reqMsg.getId());
        GrandChildProto.GrandChildRankDetailInfoCrossRespMsg.Builder respMsg = GrandChildProto.GrandChildRankDetailInfoCrossRespMsg.newBuilder();
        respMsg.setFromUserId(reqMsg.getFromUserId());
        respMsg.setFromServerId(reqMsg.getFromServerId());
        if(null == grandChildData){
            respMsg.setRet(GameErrorCode.E_GRAND_CHILD_NO_EXIST);
        }else {
            respMsg.setRet(0);
            respMsg.setGrandChild(GrandChildPb.parseGrandChildMsg(grandChildData));
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_GET_GRAND_CHILD_RANK_DETAIL_INFO_RETURN, respMsg);
        GamePlayerMgr.sendPacket(0, message);
    }
}
